
<?php include './application/views/top.php'; ?>
<script src="/static/js/ajaxfileupload.js"></script>
<script src="/static/js/gsdai.js"></script>
<script src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="/static/js/formCheck.js"></script>

<div class="clear"></div>
<div class="user_bottom all"></div>
<div class="clear h50"></div>
<div class="layout uc">
	<?php include './application/views/user/left.php'; ?>
	<div class="right">
		<div class="menu_list"><?php include './application/views/user/menu.php'; ?></div>
        <div class="cont">
		<form id="release_form" method="post">
		<input type="hidden" name="act"  value="submit">
        	<dl class="line">
            	<dt>标题：</dt>
                <dd><input name="title" class="input" id="title" maxlength="50"  ></dd>
			</dl>
        	<dl class="line">
            	<dt>内容：</dt>
                <dd><textarea rows="6" cols="35" name="contents" id="contents"></textarea></dd>
			</dl>
        	<div class="cb"><input class="button" type="submit" value="提交留言" onclick="submitLeaveword();"/></div>
		</form>
		</div>
	</div>
</div>
<div id="dialog" title="系统提示" style="display:none"><p id="msg" style="text-align:center"></p></div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script>
function submitLeaveword(){
	var options = {
		url : '/leaveword/release/',
		clearForm :true,
		resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$("#msg").html("操作成功");
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						if(ret.url==''){
							window.location.reload();
						}else{
							location=ret.url;
						}
					}
				}); 
			}else{
				$("#msg").html(ret.msg);
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
			}
		}
	};
	$("#release_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var err = '';
	var title = $('#title').val();
	var contents = $('#contents').val();
	if(title == '') {
		err = '标题不能为空';
		
	}else if(contents == ''){
		err = '内容不能为空';
	};
	 
	for(var i = 1; i<title.length; i++){
		if (i >=50) err = '标题在1-50个汉字之间';
	}

	for(var j = 1; j<contents.length; j++){
		if (j >1000) err = '内容不能超过1000个字';
	}
	
	if(err==''){
		return true;
	}else{
		$("#msg").html(err);
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}}
		}); 
		return false;
	}
}
</script>